/**
 * 
 */

var tableForm = {
	replaceExceptionChart : /\r\n/g,
	tableToForm : function(){
		var inputs = document.getElementsByName('editFormHidden');
		for(var i = 0;i<inputs.length;i++){
			var inputtype = eval(inputs[i].value.replace(this.replaceExceptionChart,' '))[0].type;
			if(inputtype == 'input')
				this.toinput(inputs[i]);
			if(inputtype == 'select')
				this.toselect(inputs[i]);
			if(inputtype == 'textarea')
				this.totextarea(inputs[i]);
			if(inputtype == 'customize')
				this.tocustomize(inputs[i]);
		}
	},
	formReturnTable : function(){
		var inputs = document.getElementsByName('editFormHidden');
		for(var i = 0;i<inputs.length;i++){
			inputs[i].parentNode.innerHTML = 
				(eval(inputs[i].value)[0].showText+this.getHiddenHTML(inputs[i]));
		}
	},
	getHiddenHTML : function(hiddenObj){
		var hiddenHTML = '';
		hiddenHTML += '<input type="hidden" name="editFormHidden" value="';
		hiddenHTML += hiddenObj.value+'"/>';
		return hiddenHTML;
	},
	toinput : function(hiddenObj){
		var j = eval(hiddenObj.value)[0];
		var newHTML = '<input type="text" ';
		newHTML += 'name = "'+j.name+'"';
		newHTML += 'id = "'+j.id+'"';
		newHTML += 'value = "'+j.value+'"';
		newHTML += 'maxlength = "'+j.maxlength+'"';
		newHTML += ' />';
		if( j.mustEnter == 'yes')
			newHTML += '&nbsp;<span style="color:red;">*</span>';
		hiddenObj.parentNode.innerHTML = (newHTML+this.getHiddenHTML(hiddenObj));
	},
	toselect : function(hiddenObj){
		var j = eval(hiddenObj.value)[0];
		var newHTML = '<select ';
		newHTML += 'name = "'+j.name+'"';
		newHTML += 'id = "'+j.id+'"';
		newHTML += ' >';
		for(var i = 0;i<j.value.split('|').length;i++){
			var s = j.value.split('|')[i].split('&');
			newHTML += '<option value="'+s[0]+'"';
			if(s[0] == j.defaultSelect){
				newHTML +=' selected="selected" ';
			}
			newHTML += '>'+s[1]+'</option>';
		}
		newHTML += '</select>';
		hiddenObj.parentNode.innerHTML = (newHTML+this.getHiddenHTML(hiddenObj));
	},
	totextarea : function(hiddenObj){
		var j = eval(hiddenObj.value.replace(this.replaceExceptionChart,' '))[0];
		var newHTML = '<textarea  rows="3" cols="20" ';
		newHTML += 'name = "'+j.name+'"';
		newHTML += 'id = "'+j.id+'"';
		newHTML += ' />'+ j.value +'</textarea>';
		if( j.mustEnter == 'yes')
			newHTML += '&nbsp;<span style="color:red;">*</span>';
		hiddenObj.parentNode.innerHTML = (newHTML+this.getHiddenHTML(hiddenObj));
	},
	tocustomize : function(hiddenObj){
		var j = eval(hiddenObj.value)[0];
		var newHTML = document.getElementById(j.customizeId).innerHTML;
		hiddenObj.parentNode.innerHTML = (newHTML+this.getHiddenHTML(hiddenObj));
	}
};